package com.chixing.day13_list.homework;

import com.chixing.day03_oop.Product;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;

public class Produce {
    private String proName;
    private int proId;
    private float proValue;

    Produce(String name,int id,float value){
        this.proName = name;
        this.proId = id;
        this.proValue = value;
    }

    @Override
    public String toString() {
        return "Produce{" +
                "proName='" + proName + '\'' +
                ", proId=" + proId +
                ", proValue=" + proValue +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Produce)) return false;
        Produce produce = (Produce) o;
        return getProId() == produce.getProId() && Float.compare(produce.getProValue(), getProValue()) == 0 && Objects.equals(getProName(), produce.getProName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getProName(), getProId(), getProValue());
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public int getProId() {
        return proId;
    }

    public void setProId(int proId) {
        this.proId = proId;
    }

    public float getProValue() {
        return proValue;
    }

    public void setProValue(float proValue) {
        this.proValue = proValue;
    }

    public static class Test{
        public static void main(String[] args) {
            Produce pro1 = new Produce("pe",5,233f);
            Produce pro2 = new Produce("cake",1,23f);
            Produce pro3 = new Produce("car",2,22f);
            Produce pro4 = new Produce("cake",1,213f);
            Produce pro5 = new Produce("cat",4,1123f);
            HashSet<Produce> produces = new HashSet<>();
            produces.add(pro1);
            produces.add(pro2);
            produces.add(pro3);
            produces.add(pro4);
            produces.add(pro5);

            produces.add(new Produce("water",23,1f));
            produces.add(new Produce("water",23,1f));

            Iterator<Produce> it = produces.iterator();
            while (it.hasNext()){
                System.out.println(it.next());
            }

            ArrayList<Produce> produce = new ArrayList<>();
            Iterator<Produce> pro = produces.iterator();
            while (pro.hasNext()){
                Produce produce1 = pro.next();
                if (produce1.getProValue()>300){
                    produce.add(produce1);

            }
                System.out.println(produce);

            }
        }
    }
}
